#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 
# Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
# 

"""
File: run10.py
Author: zhangyang(zhangyang40@baidu.com)
Date: 2018/1/5 0005 13:15
"""
"""
输入一个链表，输出该链表中倒数第k个结点。
"""


class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution:
    def FindKthToTail(self, head, k):
        p = head
        pre = head
        a = k
        count = 0
        while p is not None:
            p = p.next
            count += 1
            if k < 1:
                pre = pre.next
            k -= 1
        if count < a:
            return None
        return pre
